<?php
require("../conf/conf.php");

class Xml{
	public static function insertXml($nodeName,$nodeValue,$propertyArr){

		$path =  Conf::$xmlpath;

		$doc = DOMDocument::load($path);
		// we want a nice output
		$doc->formatOutput = true;

		$root = $doc->getElementsByTagName('code')->item(0);

		$title = $doc->createElement($nodeName);
		$title = $root->appendChild($title);
		$title->setAttribute('author', $propertyArr['author']);
		$title->setAttribute('date', $propertyArr['date']);
		$title->setAttribute('common', $propertyArr['common']);

		$text = $doc->createCDATASection($nodeValue);
		$text = $title->appendChild($text);

		echo $doc->save($path); // Wrote: 72 bytes

	}
}

function init(){
	if(isset($_POST["title"]) && isset($_POST["code"])){
		$propertyArr = array(
			'author'	=>	$_POST['author'],
			'date'		=>	$_POST['time'],
			'common'	=>	''
		);
		Xml::insertXml($_POST["title"], stripslashes($_POST["code"]), $propertyArr);
	}
}

init();
?>